﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MediaClient.Common;
using System.Threading;

namespace MediaClient.ImportMedia
{
    public partial class TransFileForm : BaseSmallForm
    {
        public static string sourceFile = "";

        public static string targetFile = "";

        static double present = 0;

        public static ConvertHelper convertApp = new ConvertHelper();

        public TransFileForm()
        {
            InitializeComponent();
        }

        private void btnSoufceFileBrower_Click(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();
            file.RestoreDirectory = true;
            file.Filter = "MPEG FILL(*.mpg)|*.mpg";
            if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                sourceFile = file.FileName;
                tbxSourceFilePath.Text = sourceFile;
            }
        }

        private void btnTargetFileBrower_Click(object sender, EventArgs e)
        {
            SaveFileDialog file = new SaveFileDialog();
            file.Filter = "MPEG FILL(*.mpg)|*.mpg";
            if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                targetFile = file.FileName;
                tbxTargetFillPath.Text = targetFile;
            }
        }

        private void btnInitialConvert_Click(object sender, EventArgs e)
        {
            if (convertApp != null)
            {
                convertApp.InitialFlexConvert(sourceFile, targetFile);
                Thread.Sleep(1000);
            }
        }

        private void btnStartConvert_Click(object sender, EventArgs e)
        {
            if (convertApp != null)
            {
                convertApp.StartFlexConvert();
                Thread.Sleep(200);
                timer.Start();
                btnInitialConvert.Enabled = false;
                btnStartConvert.Enabled = false;
            }
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            if (convertApp != null)
            {
                int num = Convert.ToInt32(convertApp.GetProcess() * 100);
                progressBar1.Value = num;               
                if (num >= 100)
                {
                    timer.Stop();
                    btnInitialConvert.Enabled = true;
                    btnStartConvert.Enabled = true;
                }
            }
        }

        private void btnButton_MouseMove(object sender, MouseEventArgs e)
        {
            Button btnControl = sender as Button;
            if (btnControl != null)
            {
                switch (btnControl.Name)
                {
                    case "btnSoufceFileBrower":
                        btnSoufceFileBrower.Image = global::MediaClient.Properties.Resources.浏览_1;
                        break;
                    case "btnTargetFileBrower":
                        btnTargetFileBrower.Image = global::MediaClient.Properties.Resources.浏览_1;
                        break;
                    case "btnInitialConvert":
                        btnInitialConvert.Image = global::MediaClient.Properties.Resources.初始化_1;
                        break;
                    case "btnStartConvert":
                        btnStartConvert.Image = global::MediaClient.Properties.Resources.开始转码_1;
                        break;
                }
            }
        }

        private void btnButton_MouseLeave(object sender, EventArgs e)
        {
            Button btnControl = sender as Button;
            if (btnControl != null)
            {
                switch (btnControl.Name)
                {
                    case "btnSoufceFileBrower":
                        btnSoufceFileBrower.Image = global::MediaClient.Properties.Resources.浏览;
                        break;
                    case "btnTargetFileBrower":
                        btnTargetFileBrower.Image = global::MediaClient.Properties.Resources.浏览;
                        break;
                    case "btnInitialConvert":
                        btnInitialConvert.Image = global::MediaClient.Properties.Resources.初始化;
                        break;
                    case "btnStartConvert":
                        btnStartConvert.Image = global::MediaClient.Properties.Resources.开始转码;
                        break;
                }
            }
        }
    }
}
